<?php
$ctype_query = "select * from tbl_company_type";
$ctype_result = mysql_query($ctype_query);

$rpt_query = "select * from tbl_reporting_type";
$rpt_result = mysql_query($rpt_query);

if($_POST['csubmit'] == 'Create')
{
	extract($_POST);
	$insert_query = "INSERT INTO tbl_companies (c_name,c_nickname,c_billing_address1,c_billing_address2,c_billing_city," .
			"c_billing_state,c_billing_zipcode,c_billing_country,c_phone_number,c_phone_extension,c_fax_number,reporting_type,ct_id) " .
			"values ('$c_name','$c_nickname','$c_billing_address1','$c_billing_address2','$c_billing_city','$c_billing_state','$c_billing_zipcode','$c_billing_country','$c_phone_number','$c_phone_extension','$c_fax_number','$reporting_type','$c_type')";
	if(mysql_query($insert_query)){?>
	<script>
	$(document).ready(function(){
//		$("#success").text("The new Company Profile has been created.").show();
		$( "#dialog:ui-dialog" ).dialog( "destroy" );
			$( "#dialog-message1" ).dialog({
			modal: true,
			buttons: {
				Ok: function() {
					$(this).dialog( "close" );
					window.location = "index.php?page=company-mang";
				}
			}
			});
	});
	</script>
	<?
	}
}

?>
<script type="text/javascript">
  $(document).ready(function(){
    $("#add_cmpyfrm").validate();
  });
</script>
<!-- ui-dialog -->
<div id="dialog-message1" title="Success Message" style="display:none;">
	<p>
		<span class="ui-icon ui-icon-circle-check" style="float:left; margin:0 7px 50px 0;"></span>
		The new Company Profile has been created.
	</p>
</div>
<span id='error'></span><span id='success'></span>
<fieldset>
<legend><strong> New Company Profile </strong></legend>
<form action="index.php?page=new-company-profile" method="post" id="add_cmpyfrm">
	<table cellpadding="4">
		<tr>
			<td><strong>Company Name* :</strong></td>
			<td><input type="text" name="c_name" class="required"/></td>
		</tr>
		<tr>
			<td><strong>Company Nickname* :</strong></td>
			<td><input type="text" name="c_nickname" class="required"/></td>
		</tr>
		<tr>
			<td><strong>Company Type* :</strong></td>
			<td>
			<select name="c_type">
			<? while($ct_row = mysql_fetch_array($ctype_result)){?>
				<option value=<? echo $ct_row['ct_id'];?> class="required"><? echo $ct_row['ct_company'];?></option>
			<? }?>				
			</select>
			</td>
		</tr>
		<tr>
			<td><strong>Reporting Type :</strong></td>
			<td>
			<select name="reporting_type">
			<option value="---"> --- </option>
			<? while($rpt = mysql_fetch_array($rpt_result)){?>
				<option value=<? echo $rpt['rpt_id'];?> ><? echo $rpt['reporting_type'];?></option>
			<? }?>				
			</select>
			</td>
		</tr>
		<tr>
			<td><strong>Billing Address1 :</strong></td>
			<td><input type="text" name="c_billing_address1" /></td>
		</tr>
		<tr>
			<td><strong>Billing Address2 :</strong></td>
			<td><input type="text" name="c_billing_address2" /></td>
		</tr>
		<tr>
			<td><strong>City :</strong></td>
			<td><input type="text" name="c_billing_city" /></td>
		</tr>
		<tr>
			<td><strong>State :</strong></td>
			<td><input type="text" name="c_billing_state" /></td>
		</tr>
		<tr>
			<td><strong>Zip Code :</strong></td>
			<td><input type="text" name="c_billing_zipcode" /></td>
		</tr>
		<tr>
			<td><strong>Country :</strong></td>
			<td><input type="text" name="c_billing_country" /></td>
		</tr>
		<tr>
			<td><strong>Phone Number :</strong></td>
			<td><input type="text" name="c_phone_number" class="number" /></td>
		</tr>
		<tr>
			<td><strong>Extension :</strong></td>
			<td><input type="text" name="c_phone_extension" class="number" /></td>
		</tr>
		<tr>
			<td><strong>Fax Number :</strong></td>
			<td><input type="text" name="c_fax_number" class="number" /></td>
		</tr>
		<tr>
			<td>&nbsp;</td>
			<td>
			<input type="submit" value="Create" name="csubmit" />
			<input type="button" value="Cancel" name="cancel" onclick="location.href='index.php?page=company-mang'"/>
			</td>
		</tr>
	</table>
</form>
</fieldset>